
package com.huizhan.web.controller;

import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.*;
import org.springframework.data.domain.Sort.*;
import io.swagger.annotations.*;

import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.*;

import com.huizhan.web.view.*;
import com.huizhan.web.dao.*;
import com.huizhan.web.model.*;
import com.huizhan.web.model.ContactInvite;

/**
 * 联系人邀约api
 */
 
@Api(tags = "ContactInvite",description = "联系人邀约")
@RestController
public class ContactInviteController {
    
    @Autowired
    private ContactInviteDao dao;
   
    @Autowired
    private InviteDao iDao;
   
    @Autowired
    private ProjectDao pDao;
   

    /**
     * 根据ID获取联系人信息
     * @param id 联系人ID
     * @return api结果
     */
    @ApiOperation(value = "根据ID获取联系人信息")
    @RequestMapping(value =  "/api/ContactInvite/{id}",method = {RequestMethod.GET})
    public ApiResult<ContactInvite> Get(@PathVariable Long id){
        ApiResult<ContactInvite> result=new ApiResult<ContactInvite>();
        try
        {
            ContactInvite model= dao.getOne(id);
            result.setData(model);
        }catch(Exception e){
            result.setHasError(true);
            result.setMessage(e.getMessage());
        }
        return  result;
    }


    /**
     * 查询联系人员分页
     * @param model 账号联系人员信息
     * @return api结果
     */
    @ApiOperation(value = "查询观众分页")
    @RequestMapping(value =  "/api/ContactInvite/Search",method = {RequestMethod.POST})
    public ApiResult<List<ContactInvite>> Search(@RequestBody PagePersonal model){
         ApiResult<List<ContactInvite>> result=new ApiResult<List<ContactInvite>>();
         
        try
        {     
            Long start=model.getStartDate().getTime()/1000;
            Long end=model.getEndDate().getTime()/1000;
            PageRequest pageable = PageRequest.of(model.getPageIndex(),model.getPageSize(),Direction.DESC,"Contact_Invite_Id") ;            
            Page<ContactInvite> page = dao.findByAll(model.getName(),model.getPhone(),model.getProjectId(),model.getCode(),start,end,model.getExhibitorId(),pageable);
            result.setData(page.getContent());
            result.setTotal(page.getTotalElements());
        }catch(Exception e){
            result.setHasError(true);
            result.setMessage(e.getMessage());
        }
        return result;
    }

    /**
     * 删除联系人信息
     * @param id 联系人ID
     * @return api结果
     */
    @ApiOperation(value = "删除联系人信息")
    @RequestMapping(value =  "/api/ContactInvite/{id}",method = {RequestMethod.DELETE})
    public ApiResult<Object> Delete(@PathVariable  Long id){
        ApiResult<Object> result=new ApiResult<Object>();
        try 
        {
            dao.deleteById(id);
        }catch(Exception e){
            result.setHasError(true);
            result.setMessage(e.getMessage());
        }
        return result;
    }
}

